package com.heatup.apt.api.service.impl;

import com.heatup.apt.model.order.OrderVoucher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.heatup.apt.common.dao.OrderVoucherMapper;
import com.heatup.apt.api.service.OrderVoucherService;
import com.baomidou.framework.service.impl.SuperServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * OrderVoucher 表数据服务层接口实现类
 *
 */
@Service
public class OrderVoucherServiceImpl extends SuperServiceImpl<OrderVoucherMapper, OrderVoucher> implements OrderVoucherService {

    Logger logger = LoggerFactory.getLogger(OrderVoucherServiceImpl.class);

    @Resource
    private OrderVoucherMapper orderVoucherMapper;

    /**
     *@Author: timo
     *@Date: 2018/3/26 10:50
     *@Description:
     * 创建订单票据
     *
     */
    @Override
    public int createOrderVoucher(List<String> imgUrls, String billType, Integer orderId, Integer userId, String remark, Integer createBy) {
        if(imgUrls != null && imgUrls.size() > 0){
            List<OrderVoucher> orderVoucherList = new ArrayList<>();
            for (String imgUrl : imgUrls){
                OrderVoucher ov = new OrderVoucher();
                ov.setImgType(billType);
                ov.setImgUrl(imgUrl);
                ov.setOrderId(orderId);
                ov.setOpendOrderUserId(userId);
                ov.setRemark(remark);
                ov.setCreateBy(createBy+"");
                ov.setCreateTime(new Date());
                orderVoucherList.add(ov);
            }
            if (orderVoucherList.size() > 0) return orderVoucherMapper.insertBatch(orderVoucherList);
        }
        logger.info(" createOrderVoucher not data insert");
        return 0;
    }
}